package com.xiaochong.tir.manager.util;


import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import com.xiaochong.tir.common.data.po.Navigation;


/**
 * 类名称：MenuTreeUtil 类描述：递归构造树型结构
 */
public class MenuTreeUtil {

	public static Map<String, Object> mapArray = new LinkedHashMap<String, Object>();
	public List<Navigation> menuCommon;
	public List<Navigation> menuCommon2;
	public List<Object> list = new ArrayList<Object>();
	public List<Object> list2 = new ArrayList<Object>();

	public List<Object> menuList(List<Navigation> menu) {
		this.menuCommon = menu;
		for (Navigation x : menu) {
			Map<String, Object> mapArr = new LinkedHashMap<String, Object>();
			if (x.getParentId() == 0) {
				mapArr.put("value", x.getId());
				mapArr.put("title", x.getTitle());
				mapArr.put("checked", x.getCount()>0?true:false);
				mapArr.put("data", menuChild(x.getId()));
				list.add(mapArr);
			}
		}
		return list;
	}

	public List<?> menuChild(int id) {
		List<Object> lists = new ArrayList<Object>();
		for (Navigation a : menuCommon) {
			Map<String, Object> childArray = new LinkedHashMap<String, Object>();
			if (a.getParentId() == id) {
				childArray.put("value", a.getId());
				childArray.put("title", a.getTitle());
				childArray.put("checked", a.getCount()>0?true:false);
				childArray.put("data", menuChild(a.getId()));
				lists.add(childArray);
			}
		}
		return lists;
	}
	
	
	public List<Object> menuList2(List<Navigation> menu) {
		this.menuCommon2 = menu;
		for (Navigation x : menu) {
			Map<String, Object> mapArr = new LinkedHashMap<String, Object>();
			if (x.getParentId() == 0) {
				mapArr.put("icon", x.getIcon());
				mapArr.put("title", x.getTitle());
				mapArr.put("href", x.getHref());
				mapArr.put("spread", x.getSpread());
				mapArr.put("children", menuChild2(x.getId()));
				list2.add(mapArr);
			}
		}
		return list2;
	}

	public List<?> menuChild2(int id) {
		List<Object> lists = new ArrayList<Object>();
		for (Navigation a : menuCommon2) {
			Map<String, Object> childArray = new LinkedHashMap<String, Object>();
			if (a.getParentId() == id) {
				childArray.put("icon", a.getIcon());
				childArray.put("title", a.getTitle());
				childArray.put("href", a.getHref());
				childArray.put("spread", a.getSpread());
				childArray.put("children", menuChild2(a.getId()));
				lists.add(childArray);
			}
		}
		return lists;
	}

}